package pattern.creational.singleton;

public class SingleDemo {
	
	public void getRun() {
		NumThread threadA = new NumThread("线程A");
		NumThread threadB = new NumThread("线程B");
		threadA.start();
		threadB.start();
	}

	class NumThread extends Thread{
		private String threadName;
		public NumThread(String name){
			threadName = name;
		}
		public void run(){
			GlobalNum gnObj = GlobalNum.getInstance();
			for(int i=0;i<5;i++){
				System.out.println(threadName+"第"+gnObj.getNum()+"次访问！");
				try{
					this.sleep(1000);
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
	}
	
	public static void main(String[] args) {
		SingleDemo demo = new SingleDemo();
		demo.getRun();
	}
}
